package com.haihui.platform.controller.sys;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.haihui.platform.controller.BaseController;
import com.haihui.platform.entity.CemeteryCostSet;
import com.haihui.platform.service.sys.CemeteryCostSetService;

@Controller
@RequestMapping("cost")
public class CemeteryCostSetController extends BaseController{

	private static final Logger LOG = Logger.getLogger(CemeteryCostSetController.class);

	@Autowired
	private CemeteryCostSetService cemeteryCostSetService;

	/**
	 * 费用列表
	 * @param start
	 * @param length
	 */
	@RequestMapping(value="/list")
	public void list(CemeteryCostSet cem){
		try{
			int count = cemeteryCostSetService.count(cem);
			List<CemeteryCostSet> list = cemeteryCostSetService.list(cem);
			this.responseWriter(this.getCommonJsonPage(count, list));
		}catch(Exception e){
			LOG.error(e.getMessage(),e);
			this.responseWriter(this.getCommonJsonString(false, "查询失败"));
		}
	}
	
	/**
	 * 新增费用
	 */
	@RequestMapping(value="/add")
	public void add(CemeteryCostSet cem){
		try{
			int count = cemeteryCostSetService.add(cem);
			this.responseWriter(this.getCommonJsonString(true, "新增成功", count));
		}catch(Exception e){
			LOG.error(e.getMessage(),e);
			this.responseWriter(this.getCommonJsonString(false, "新增失败"));
		}
	}
	
	/**
	 * 修改费用
	 */
	@RequestMapping(value="/update")
	public void update(CemeteryCostSet cem){
		try{
			int count = cemeteryCostSetService.update(cem);
			this.responseWriter(this.getCommonJsonString(true, "修改成功", count));
		}catch(Exception e){
			LOG.error(e.getMessage(),e);
			this.responseWriter(this.getCommonJsonString(false, "修改失败"));
		}
	}
	
	/**
	 * 费用详情
	 */
	@RequestMapping(value="/detail")
	public void detail(CemeteryCostSet cem){
		try{
			CemeteryCostSet m = cemeteryCostSetService.detail(cem);
			this.responseWriter(this.getCommonJsonString(true, "查询成功", m));
		}catch(Exception e){
			LOG.error(e.getMessage(),e);
			this.responseWriter(this.getCommonJsonString(false, "查询失败"));
		}
	}
	
	/**
	 * 删除费用
	 */
	@RequestMapping(value="/delete")
	public void delete(CemeteryCostSet cem){
		try{
			int count = cemeteryCostSetService.delete(cem);
			this.responseWriter(this.getCommonJsonString(true, "删除成功", count));
		}catch(Exception e){
			LOG.error(e.getMessage(),e);
			this.responseWriter(this.getCommonJsonString(false, "删除失败"));
		}
	}
	
}